<script setup lang="ts">
import type {
  FormDesignerComponents,
  FormItemPerm
} from "../FormComponentMixin";
import { isReadonly } from "../FormItem";
const props = defineProps({
  type: {
    type: String,
    default: ""
  },
  mode: {
    type: String,
    default: "normal" //组件模式，free设计模式，normal 编辑模式, read 阅读模式，disable 禁用模式
  }
});
//组件值
const _value = defineModel<string>();
const config = defineModel<FormDesignerComponents>("config");
const perm = inject<Array<FormItemPerm>>("perm");
const disabled = computed(() => {
  if (props.mode === "disable" && isReadonly(perm, config.value.code)) {
    return true;
  }
  return false;
});

const readonly = computed(() => {
  if (props.mode === "read" || isReadonly(perm, config.value.code)) {
    return true;
  }
  return false;
});
</script>

<template>
  <el-input
    v-model="_value"
    :show-word-limit="true"
    :rows="config.props.rows"
    type="textarea"
    :maxlength="config.props.maxlength || 255"
    :placeholder="config.props.placeholder"
    :disabled="disabled"
    :readonly="readonly"
    clearable
    style="width: 95%"
  />
</template>

<style scoped></style>
